/**
 * 仿真面板相关
 */
import { defineStore } from "pinia";
import { ref, computed } from "vue";

// 定义面板信息类型
interface SimulPanelInfo {
  // 面板初始大小
  width: number;
  height: number;
  // 面板位置信息
  screenX: number;
  screenY: number;
  left: number;
  top: number;
  // 调整大小
  resize: boolean;
  // 是否显示面板
  isShowPanel: boolean;
}

// 原有的 store 保留用于向后兼容
export const simulPanelState = defineStore("simul-panel", () => {
  const simulPanelInfo = ref<SimulPanelInfo>({
    // 面板初始大小
    width: 0,
    height: 0,
    // 面板位置信息
    screenX: 0,
    screenY: 0,
    left: 0,
    top: 0,
    // 调整大小
    resize: false,
    // 是否显示面板
    isShowPanel: false,
  });

  // 添加控制面板状态
  const statusPanelShow = ref(true);
  const controlPanelShow = ref(true);
  const entityPanelShow = ref(false);
  const logPanelShow = ref(false);

  function togglePanel() {
    simulPanelInfo.value.isShowPanel = !simulPanelInfo.value.isShowPanel;
  }

  function setSimulPanelInfo(info: SimulPanelInfo) {
    simulPanelInfo.value = {
      ...simulPanelInfo.value,
      ...info,
    };
  }

  // 添加控制面板的方法
  function setStatusPanelShow(flag: boolean) {
    statusPanelShow.value = flag;
  }

  function setControlPanelShow(flag: boolean) {
    controlPanelShow.value = flag;
  }

  function setEntityPanelShow(flag: boolean) {
    entityPanelShow.value = flag;
  }

  function setLogPanelShow(flag: boolean) {
    logPanelShow.value = flag;
  }

  // 获取面板信息
  const getSimulPanelInfo = computed(() => simulPanelInfo.value);

  return {
    simulPanelInfo,
    getSimulPanelInfo,
    togglePanel,
    setSimulPanelInfo,
    // 添加控制面板状态和方法的导出
    statusPanelShow,
    controlPanelShow,
    entityPanelShow,
    logPanelShow,
    setStatusPanelShow,
    setControlPanelShow,
    setEntityPanelShow,
    setLogPanelShow,
  };
});
